<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Album
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: Controller.php 9241 2011-09-07 01:35:47Z shaun $
 * @author     Sami
 */

/**
 * @category   Application_Extensions
 * @package    Album
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Ialbum_Widget_ProfileAlbumsController extends Engine_Content_Widget_Abstract
{
  protected $_childCount;
  
  public function indexAction()
  {
    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }

    // Get subject and check auth
    $subject = Engine_Api::_()->core()->getSubject();
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
      return $this->setNoRender();
    }

    // Get al_paginator
    $this->view->al_paginator = $al_paginator = Engine_Api::_()->getItemTable('album')->getAlbumpaginator(array('owner' => $subject, 'search' => 1));

    // Set item count per page and current page number
    $al_paginator->setItemCountPerPage($this->_getParam('albums_itemCountPerPage', 8));
    $al_paginator->setCurrentPageNumber($this->_getParam('page_al', 1));
	
    //get photos paginator
    $this->view->pho_paginator = $pho_paginator =  Engine_Api::_()->ialbum()->getFreindTaggedPhoto(array($subject->getIdentity()));
    $pho_paginator->setItemCountPerPage($this->_getParam('photos_itemCountPerPage', 8));
    $pho_paginator->setCurrentPageNumber($this->_getParam('page_pho', 1));
    $this->view->isAjaxPhoto = $isAjaxPhoto = $this->_getParam('isAjaxPhoto', false);
    if($isAjaxPhoto){
    	$this->getElement()->removeDecorator('Title');
    	$this->getElement()->removeDecorator('Container');
    }
    // Do not render if nothing to show
    if( $al_paginator->getTotalItemCount() <= 0 && $pho_paginator->getTotalItemCount() <= 0) {
      return $this->setNoRender();
    }

    // Add count to title if configured
    if( $this->_getParam('titleCount', false) && $al_paginator->getTotalItemCount() > 0 ) {
      $this->_childCount = $al_paginator->getTotalItemCount();
    }
  }

  public function getChildCount()
  {
    return $this->_childCount;
  }
}